﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Simple.Common;
using Simple.Entity;
using Simple.Entity.Dto;
using Simple.Entity.Params;
using Simple.IService;
using Simple.Tools;

namespace Simple.Web.Core.Controllers
{
	/// <summary>
	/// 
	/// </summary>
	[Route("api/sys-user")]
	[ApiController]
	public class sysUserController : ControllerBase
	{
		/// <summary>
		/// 
		/// </summary>
		[Autowired]
		public IUserService userService { get; set; }
		/// <summary>
		/// 
		/// </summary>
		public sysUserController()
		{

		}
		/// <summary>
		/// 创建用户
		/// </summary>
		/// <param name="userDto"></param>
		/// <returns></returns>
		[HttpPost()]
		public async Task<Simple.Common.BaseMessage> AddAsync([FromBody] UserDto userDto)
		{
			return await userService.AddAsync(userDto);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="loginParames"></param>
		/// <returns></returns>
		[AllowAnonymous]
		[HttpPost("login")]
		public async Task<Simple.Common.BaseMessage> LoginAsync([FromBody] LoginParameter loginParames)
		{
			return await userService.LoginAsync(loginParames);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="Id"></param>
		/// <param name="userDto"></param>
		/// <returns></returns>
		[HttpPut("{id}")]
		public async Task<Simple.Common.BaseMessage> UpdateAsync(string Id,[FromBody] UserDto userDto)
		{
			return await userService.UpdateAsync(Id.ToInt64(), userDto);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="Id"></param>
		/// <returns></returns>
		[HttpPut("rest-password/{id}")]
		public async Task<Simple.Common.BaseMessage> RestPasswordAsync(string Id)
		{
			return await userService.RestPasswordAsync(Id.ToInt64());
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="Id"></param>
		/// <returns></returns>
		[HttpDelete("soft/{id}")]
		public async Task<Simple.Common.BaseMessage> SoftDeleteAsync(string Id)
		{
			return await userService.SoftDeleteAsync(Id.ToInt64());
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="Params"></param>
		/// <returns></returns>
		[HttpPost("page")]
		public async Task<Simple.Common.BaseMessage> GetPageAsync([FromBody] UserParameter Params )
		{
			return await userService.GetPageAsync(Params);
		}
	}
}
